package cn.e4j.modular.crm.controller.base;

import cn.e4j.core.base.controller.BaseController;
import cn.e4j.core.common.exception.BizExceptionEnum;
import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.ErrorResponseData;
import cn.e4j.core.reqres.response.PageReData;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.modular.crm.entity.MmrcT;
import cn.e4j.modular.crm.entity.MmrclT;
import cn.e4j.modular.crm.service.MmrcTService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 标准售后服务收费项目维护 控制层
 * @author mengyb
 * @date 2019-04-16
 */
@Controller
@RequestMapping("/base/gwai630")
public class Gwai630Controller extends BaseController {

    @Autowired
    private MmrcTService mmrcTService;

    /**
     * 跳转至标准评价指标维护主界面
     * @return
     */
    @RequiresPermissions("base:gwai630:init")
    @RequestMapping(value = {"","init"})
    public String index(){
        return "/pc/crm/base/gwai630.html";
    }

    @RequiresPermissions("base:gwai630:init")
    @RequestMapping("/getList")
    @ResponseBody
    public ResponseData getList(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        Page<Object> page=dtoWapper.getPage();
        List<Map<String, Object>> list = mmrcTService.getList(inDto, page);
        return new PageReData<>(page,list);
    }

    @RequiresPermissions("base:gwai630:init")
    @RequestMapping("/add")
    @ResponseBody
    public ResponseData add(MmrcT mmrcT, MmrclT mmrclT) {
        if(mmrcTService.existedTheParams(mmrcT)){
            return new ErrorResponseData(BizExceptionEnum.EXISTED_THE_PARAMS.getCode(),
                    BizExceptionEnum.EXISTED_THE_PARAMS.getMessage());
        }
        mmrcTService.add(mmrcT, mmrclT);
        return SUCCESS_TIP;
    }

    @RequiresPermissions("base:gwai630:init")
    @RequestMapping("/edit")
    @ResponseBody
    public ResponseData edit(MmrcT mmrcT, MmrclT mmrclT) {
        mmrcTService.edit(mmrcT, mmrclT);
        return SUCCESS_TIP;
    }

    @RequiresPermissions("base:gwai630:init")
    @RequestMapping("/delRow")
    @ResponseBody
    public ResponseData delRow(MmrcT mmrcT, MmrclT mmrclT) {
        mmrcTService.delRow(mmrcT, mmrclT);
        return SUCCESS_TIP;
    }

    @RequiresPermissions("base:gwai630:init")
    @RequestMapping("/delRows")
    @ResponseBody
    public ResponseData delRows(@DtoParam DtoWapper dtoWapper) {
        Dto inDto = dtoWapper.getDto();
        List<MmrcT> mmrcTList = inDto.getReqList(MmrcT.class);
        mmrcTService.delRows(mmrcTList);
        return SUCCESS_TIP;
    }

}
